|
AWT스윙GUI |
[1] |
|
등록일:2008-03-10 10:32:20 (0%) 작성자: 제목:멀티 라인 툴팁 |
|
게시글 시간: 2002/11/08 09:54:00 오전
김영익
새로운 답글 달기 새로운 답글 달기
JButton button = new JButton()
{
public JToolTip createToolTip()
{
return new JMultiLineToolTip();
}
};
button.setToolTipText("어쩌구" + "\n" + "저쩌구");
이런식으로 이너 클래스로 사용되고 소스는 아래와 같네요.
누군지 참 기특하네 이런걸 다 만들고...
#############################################################################
// JMultiLineToolTip.java
package ui;
import javax.swing.*;
import javax.swing.plaf.*;
import java.awt.*;
import java.awt.font.*;
import java.awt.event.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicToolTipUI;
import javax.swing.text.*;
/**
* @author Zafir Anjum
*/
public class JMultiLineToolTip extends JToolTip {
private static final String uiClassID = "ToolTipUI";
String tipText;
JComponent component;
public JMultiLineToolTip() {
updateUI();
}
public void updateUI() {
setUI(MultiLineToolTipUI.createUI(this));
}
public void setColumns(int columns) {
this.columns = columns;
this.fixedwidth = 0;
}
public int getColumns() {
return columns;
}
public void setFixedWidth(int width) {
this.fixedwidth = width;
this.columns = 0;
}
public int getFixedWidth() {
return fixedwidth;
}
protected int columns = 0;
protected int fixedwidth = 0;
}
class MultiLineToolTipUI extends BasicToolTipUI {
static MultiLineToolTipUI sharedInstance = new MultiLineToolTipUI();
Font smallFont;
static JToolTip tip;
protected CellRendererPane rendererPane;
private static JTextArea textArea ;
public static ComponentUI createUI(JComponent c) {
return sharedInstance;
}
public MultiLineToolTipUI() {
super();
}
public void installUI(JComponent c) {
super.installUI(c);
tip = (JToolTip)c;
rendererPane = new CellRendererPane();
c.add(rendererPane);
}
public void uninstallUI(JComponent c) {
super.uninstallUI(c);
c.remove(rendererPane);
rendererPane = null;
}
public void paint(Graphics g, JComponent c) {
Dimension size = c.getSize();
textArea.setBackground(c.getBackground());
rendererPane.paintComponent(g, textArea, c, 1, 1,
size.width - 1, size.height - 1, true);
}
public Dimension getPreferredSize(JComponent c) {
String tipText = ((JToolTip)c).getTipText();
if (tipText == null) {
return new Dimension(0,0);
}
textArea = new JTextArea(tipText );
rendererPane.removeAll();
rendererPane.add(textArea );
textArea.setWrapStyleWord(true);
int width = ((JMultiLineToolTip)c).getFixedWidth();
int columns = ((JMultiLineToolTip)c).getColumns();
if( columns > 0 ) {
textArea.setColumns(columns);
textArea.setSize(0,0);
textArea.setLineWrap(true);
textArea.setSize( textArea.getPreferredSize() );
}
else if( width > 0 ) {
textArea.setLineWrap(true);
Dimension d = textArea.getPreferredSize();
d.width = width;
d.height++;
textArea.setSize(d);
}
else {
textArea.setLineWrap(false);
}
Dimension dim = textArea.getPreferredSize();
dim.height += 1;
dim.width += 1;
return dim;
}
public Dimension getMinimumSize(JComponent c) {
return getPreferredSize(c);
}
public Dimension getMaximumSize(JComponent c) {
return getPreferredSize(c);
}
}
출처 : http://www.ibm.com/developerworks/kr/forums/dw_thread.jsp?forum=7&thread=713&cat=4 |
[본문링크] 멀티 라인 툴팁
|
[1]
|
|
|
|
|
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=2452 |
|
|
|
|
|
|
|
|
|
Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.
|
|
|